package com.SmartCampus.system.service.impl;

import com.SmartCampus.system.common.ErrorCode;
import com.SmartCampus.system.exception.BusinessException;
import com.SmartCampus.system.mapper.AttendanceMapper;
import com.SmartCampus.system.model.dto.attendance.AttendanceQueryRequest;
import com.SmartCampus.system.model.entity.Attendance;
import com.SmartCampus.system.model.vo.AttendanceVO;
import com.SmartCampus.system.service.AttendanceService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author wangliang
* @description 针对表【Attendance(签到表)】的数据库操作Service实现
* @createDate 2024-12-27 20:33:35
*/
@Service
public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attendance>
    implements AttendanceService {

    @Resource
    private AttendanceMapper attendanceMapper;

    @Override
    public Page<AttendanceVO> getAll(Page<AttendanceVO> pageParam, AttendanceQueryRequest attendanceQueryRequest) {
        List<AttendanceVO> attendances = attendanceMapper.getAll(pageParam, attendanceQueryRequest);
        if (attendances == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        pageParam.setRecords(attendances);
        return pageParam;
    }

    @Override
    public Page<AttendanceVO> getMy(Page<AttendanceVO> pageParam, AttendanceQueryRequest attendanceQueryRequest, Long userId) {
        List<AttendanceVO> attendances = attendanceMapper.getMy(pageParam, attendanceQueryRequest, userId);
        if (attendances == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(attendances);
        return pageParam;
    }
}




